apiVersion: "logging.kubesphere.io/v1alpha1"
kind: "FluentBit"
metadata:
  name: "fluent-bit"
  namespace: "kubesphere-logging-system"
spec:
  service:
    - type: fluentbit_service
      name: fluentbit-service
      parameters:
        - name: Flush
          value: "1"
        - name: Daemon
          value: "Off"
        - name: Log_Level
          value: "info"
        - name: Parsers_File
          value: "parsers.conf"
  input:
    - type: fluentbit_input
      name: fluentbit-input
      parameters:
        - name: Name
          value: "tail"
        - name: Path
          value: "/var/log/containers/*.log"
        - name: Parser
          value: "docker"
        - name: Tag
          value: "kube.*"
        - name: Refresh_Interval
          value: "5"
        - name: Mem_Buf_Limit
          value: "5MB"
        - name: Skip_Long_Lines
          value: "On"
        - name: DB
          value: "/tail-db/tail-containers-state.db"
        - name: DB.Sync
          value: "Normal"
  filter:
    - type: fluentbit_filter
      name: fluentbit-filter
      parameters:
        - name: Name
          value: "kubernetes"
        - name: Match
          value: "kube.*"
        - name: Kube_URL
          value: "https://kubernetes.default.svc:443"
        - name: Kube_CA_File
          value: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
        - name: Kube_Token_File
          value: "/var/run/secrets/kubernetes.io/serviceaccount/token"
    - type: fluentbit_filter
      name: fluentbit-filter
      parameters:
        - name: Name
          value: "nest"
        - name: Match
          value: "kube.*"
        - name: Operation
          value: "lift"
        - name: Nested_under
          value: "kubernetes"
        - name: Prefix_with
          value: "kubernetes_"
    - type: fluentbit_filter
      name: fluentbit-filter-remove-stream
      parameters:
        - name: Name
          value: "modify"
        - name: Match
          value: "kube.*"
        - name: Remove
          value: "stream"
    - type: fluentbit_filter
      name: fluentbit-filter-remove-labels
      parameters:
        - name: Name
          value: "modify"
        - name: Match
          value: "kube.*"
        - name: Remove
          value: "kubernetes_labels"
    - type: fluentbit_filter
      name: fluentbit-filter-remove-annotations
      parameters:
        - name: Name
          value: "modify"
        - name: Match
          value: "kube.*"
        - name: Remove
          value: "kubernetes_annotations"
    - type: fluentbit_filter
      name: fluentbit-filter-remove-podid
      parameters:
        - name: Name
          value: "modify"
        - name: Match
          value: "kube.*"
        - name: Remove
          value: "kubernetes_pod_id"
    - type: fluentbit_filter
      name: fluentbit-filter-nest
      parameters:
        - name: Name
          value: "nest"
        - name: Match
          value: "kube.*"
        - name: Operation
          value: "nest"
        - name: Wildcard
          value: "kubernetes_*"
        - name: Nested_under
          value: "kubernetes"
        - name: Remove_prefix
          value: "kubernetes_"
  output:
    - type: fluentbit_output
      name: fluentbit-output
      parameters:
        - name: Name
          value: "es"
        - name: Match
          value: "kube.*"
        - name: Host
          value: "{% if logging.externalElasticsearchUrl is defined %}{{ logging.externalElasticsearchUrl }}{% else %}elasticsearch-logging-data.kubesphere-logging-system.svc{% endif %}"
        - name: Port
          value: "{% if logging.externalElasticsearchPort is defined %}{{ logging.externalElasticsearchPort }}{% else %}9200{% endif %}"
        - name: Logstash_Format
          value: "On"
        - name: Replace_Dots
          value: "on"
        - name: Retry_Limit
          value: "False"
        - name: Type
          value: "flb_type"
        - name: Time_Key
          value: "@timestamp"
        - name: Logstash_Prefix
          value: "ks-{{ logging.elkPrefix }}-log"
  settings:
    - type: fluentbit_settings
      name: fluentbit-settings
      parameters:
        - name: Enable
          value: "true"

